package com.appkubes.mall.restful.config.camel;

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;
import java.util.List;

@Configuration
public class CamelConfig implements WebMvcConfigurer {

    @Resource
    private CamelFilter camelFilter;

    @Resource
    private UnderlineToCamelArgumentResolver underlineToCamelArgumentResolver;

    /**
     * 解决bean入参下滑线转驼峰
     *
     * @param resolvers
     */
    @Override
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
        resolvers.add(underlineToCamelArgumentResolver);
    }

    /**
     * 解决requestParams入参下划线转驼峰
     *
     * @return
     */
    @Bean
    public FilterRegistrationBean<CamelFilter> registration() {
        FilterRegistrationBean<CamelFilter> registration = new FilterRegistrationBean<>(camelFilter);
        registration.addUrlPatterns("/api/*");
        registration.addUrlPatterns("/saas_credit/*");
        return registration;
    }
}